<div class="box-header with-border">
    <h3 class="box-title">二维码设置</h3>
    <!-- /.box-tools -->
</div>
<!-- /.box-header -->

<form role="form" onsubmit="return sub_setting_7()">
    <input type="hidden" name="qrcode_back" id="qrcode_back" value="{$sys['qrcode_back']}">
    <div class="box-body">
        <div class="form-group">
            <label for="qrcode_url">二维码推广链接</label>
            <input type="text" class="form-control" value="{$sys['qrcode_url']}" id="qrcode_url" placeholder="二维码推广链接">
        </div>
        <div class="form-group">
            <label for="qrcode_size">二维码图片大小</label>
            <input type="text" class="form-control" value="{$sys['qrcode_size']}" onkeyup="sub_setting_7()" id="qrcode_size" placeholder="二维码推广链接">
        </div>
        <div class="form-group">
            <label for="back_x">背景图坐标X</label>
            <input type="text" class="form-control" value="{$sys['back_x']}" onkeyup="sub_setting_7()" id="back_x" placeholder="背景图坐标X">
        </div>
        <div class="form-group">
            <label for="back_y">背景图坐标Y</label>
            <input type="text" class="form-control" value="{$sys['back_y']}" onkeyup="sub_setting_7()" id="back_y" placeholder="背景图坐标Y">
        </div>
        <div class="form-group">
            <label for="qrcode_back">二维图背景图</label>
            <input id="fileupload" type="file" name="files" accept=".jpg">
            <div class="progress progress-striped active" style="width:300px;">
                <div class="progress-bar progress-bar-success" role="progressbar" style="width:0%;">0%</div>
            </div>
            <img id="showimg" src="" width="250px">
        </div>
    </div>
    <!-- /.box-body -->

    <div class="box-footer">
        <button type="submit" class="btn btn-primary">保存</button>
    </div>
</form>

<script>
    $(function () {
        setSrc();

        var moduleName = 'Upload';
        //选文件自动上传
        $('#fileupload').fileupload({
            dataType: 'json',
            singleFileUploads:false,
            autoUpload: true,//是否自动上传
            url : '__ADMIN__/' + moduleName + '/uploadImg',
            //url: '__CONTROLLER__/uploadImg',
            acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
            maxFileSize: 5000000,
            formData: {
                path: '__QRCODEBGPATH__',
                file_name:'/__QRCODEBGNAME__'
            },
            progressall: function (e, data) {
                var progress = parseInt(data.loaded / data.total * 100, 10);
                //console.log(progress);
                $('.progress-bar').css('width',progress + '%');
                $('.progress-bar').text(progress + '%');
            },
            done: function(e, data) {
                if (data.result.status == 0) {
                    $('.progress-bar').text(data.result.info);
                } else {
                    $('.progress-bar').text("完成");
                    setSrc();
                }
            },
            change: function (e, data) {
                $.each(data.files, function (index, file) {
                    $('.ace-file-name').attr('data-title', file.name);
                });
            }
        });
    });

    function setSrc() {
        $("#showimg").attr("src", "__ADMIN__/QRcode/temp_qrcode?back_x="+$("#back_x").val()+"&back_y="+$("#back_y").val()+"&qrcode_size="+$("#qrcode_size").val());
    }

    function sub_setting_7(){

        var qrcode_url = $("#qrcode_url").val();
        if (qrcode_url ==  "") {
            $.scojs_message("二维码推广链接不能为空", $.scojs_message.TYPE_ERROR);
            return false;
        }
        var qrcode_size = $("#qrcode_size").val();
        if (qrcode_size ==  "") {
            $.scojs_message("二维码图片大小不能为空", $.scojs_message.TYPE_ERROR);
            return false;
        }
        var back_x = $("#back_x").val();
        if (back_x ==  "") {
            $.scojs_message("背景图坐标X不能为空", $.scojs_message.TYPE_ERROR);
            return false;
        }
        var back_y = $("#back_y").val();
        if (back_y ==  "") {
            $.scojs_message("背景图坐标Y不能为空", $.scojs_message.TYPE_ERROR);
            return false;
        }
        $.ajax({
            type:"POST",
            url : '__ADMIN__/'+moduleName+'/setting',
            dataType:"json",
            data:{
                id:1,
                qrcode_url:qrcode_url,
                back_x:back_x,
                back_y:back_y,
                qrcode_size:qrcode_size
            },
            beforeSend:showLoad,
            success:function(msg) {
                if (msg.code == 0) {
                    $.scojs_message(msg.msg, $.scojs_message.TYPE_OK);
                    setSrc();
                } else {
                    $.scojs_message(msg.msg, $.scojs_message.TYPE_ERROR);
                }
                hideLoad();
            }
        });

        return false;
    }
</script>